package com.miaosha.ms_03.result;


public class Result<T> {
    //状态码
    private Integer code;

    //返回消息
    private String msg;

    //返回对象
    private T data;


    private Result(T data) {
        this.code = ResultEnum.RESULT_SUCCESS.getCode();
        this.msg = ResultEnum.RESULT_SUCCESS.getMsg();
        this.data = data;
    }
    private Result(CodeMsg err) {
        if(err == null){
            return;
        }
        this.code = err.getCode();
        this.msg = err.getMsg();
    }

    /**
     * @param data 返回数据对象
     * @Description 封装成功返回对象
     *
     */
    public static <T> Result<T> success(T data) {
        return new Result<T>(data);
    }

    /**
     * @param err 异常返回对象
     * @return void
     * @Description
     **/
    public static <T> Result<T> error(CodeMsg err) {
        return new Result<T>(err);
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }
}
